package leetcode.code0014;

public class Solution1 extends Solution0014 {

	@Override
	public String longestCommonPrefix(String[] strs) {
		char[] ans = strs[0].toCharArray();
		int len = ans.length;
		for (int i = 1; i < strs.length; i++) {
			char[] cur = strs[i].toCharArray();
			int p = 0;
			while (p < len && p < cur.length) {
				if (ans[p] == cur[p]) {
					p++;
				} else {
					break;
				}
			}
			if (p == 0)
				return "";
			len = p;
		}
		return new String(ans, 0, len);
	}

	public static void main(String[] args) {
		Solution1 so = new Solution1();
		so.debug1();
		so.debug2();

	}

}
